#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QTcpServer>
#include <QHostAddress>
#include <QStringList>
#include <QString>
#include <QObject>
#include <QPushButton>
#include <QDebug>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QFile>
#include <QProgressBar>
#include <QFile>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    QHostAddress address;
    QTcpSocket *tcpSocket;
    QLineEdit *hostIPinput;
    QLineEdit *imageInput;
    QLabel *tcpState;
    quint16 port;
    QString m_hostIP;
    QString fileName;                     //图片文件名
    QFile *file;
    QString path;                        //图片文件路径
    QByteArray imageByte;
    QPushButton *saveBtn;
    QPushButton *connectBtn;
    QPushButton *browseBtn;
    QPushButton *sendBtn;
    QPushButton *cancelBtn;
    /* 总数据大小，已发送数据大小，剩余数据大小，每次发送数据块大小 */
    qint64 fileBytes, sentBytes, restBytes, loadBytes;
    QProgressBar *sendProg;

private slots:
    void saveHostIP();
    void showTcpState();
    void tcpReConnect();
    void selectFile();
    void sendFile();
    void start_transfer();
    void continue_transfer(qint64 sentSize);
    void show_error(QAbstractSocket::SocketError);
};

#endif // MAINWINDOW_H
